package edu.whcp.comp2301.controller;

import edu.whcp.comp2301.dao.CommentDao;
import edu.whcp.comp2301.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/list")
public class CommentController {
    @Autowired
    private CommentDao commentDao;

    @RequestMapping("/comm")
    public ModelAndView list(){
        List<Comment> commentList=commentDao.getAllComments();
        return new ModelAndView("backend/comment-management","commList",commentList);
    }

    @PostMapping(value = "/alter/check",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Integer checkComment(@RequestParam String id, @RequestParam String status){
        commentDao.checkComment(status, id);
        return 1;
    }

    @PostMapping(value = "/del/comment",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Integer delComment(@RequestParam("ids") List<String> idList){
        return commentDao.delComment(idList);
    }
}
